home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mntlb20 / lib / sprintf.c < prev    next >
C/C++ Source or Header  |  1992-02-07  |  1KB  |  58 lines

  1. #include <stdarg.h>
  2. #include <stdio.h>
  3. #include <limits.h>
  4. #include "lib.h"
  5.  
  6. #ifdef __SOZOBON__    /* Electronic brain... */
  7. static FILE dummyf =
  8.     {0L, (unsigned char *)0, (unsigned char *)0,
  9.          _IOWRT|_IOBIN|_IOSTRING|_IOFBF, 0, LONG_MAX, '\0'};
  10. #endif
  11.  
  12. #if __STDC__
  13. int sprintf(char *buf, const char *fmt, ...)
  14. #else
  15. int sprintf(buf, fmt) char *buf; const char *fmt;
  16. #endif
  17. {
  18.     va_list args;
  19.     register int n;
  20. #ifndef __SOZOBON__    /* A little bit of braindeath here, methinks. */
  21.     FILE sf = 
  22.     {0L, (unsigned char *)buf, (unsigned char *)buf,
  23.          _IOWRT|_IOBIN|_IOSTRING|_IOFBF, 0, LONG_MAX,'\0'};
  24. #else
  25.     FILE sf;
  26.  
  27.     sf = dummyf;
  28.     sf._ptr = sf._base = (unsigned char *)buf;
  29. #endif
  30.     va_start(args, fmt);    
  31.     n = _doprnt(&sf, fmt, args);
  32.     *(sf._ptr) = '\0';        /* always tie off the string */
  33.     va_end(args);
  34.     return(n);
  35. }
  36.  
  37. int
  38. vsprintf(buf, fmt, args)
  39.     char *buf;
  40.     const char *fmt;
  41.     va_list args;
  42. {
  43.     register int n;
  44. #ifndef __SOZOBON__    /* Same again, please, landlord. */
  45.     FILE sf = 
  46.     {0L, (unsigned char *)buf, (unsigned char *)buf,
  47.          _IOWRT|_IOBIN|_IOSTRING|_IOFBF, 0, LONG_MAX,'\0'};
  48. #else
  49.     FILE sf;
  50.  
  51.     sf = dummyf;
  52.     sf._ptr = sf._base = (unsigned char *)buf;
  53. #endif
  54.     n = _doprnt(&sf, fmt, args);
  55.     *(sf._ptr) = '\0';        /* always tie of the string */
  56.     return(n);
  57. }
  58.